/*
 * Copyright (c) 2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.wso2.carbon.registry.social.impl.activity;

import org.wso2.carbon.registry.social.api.activity.Activity;
import org.wso2.carbon.registry.social.api.activity.MediaItem;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 *  An implementation of the {@link org.wso2.carbon.registry.social.api.activity.Activity} interface
 * 
 *
 */
public class ActivityImpl implements Activity {

    private String appId;
    private String body;
    private String bodyId;
    private String externalId;
    private String id;
    private Date updated;
    private List<MediaItem> mediaItems;
    private Long postedTime;
    private Float priority;
    private String streamFaviconUrl;
    private String streamSourceUrl;
    private String streamTitle;
    private String streamUrl;
    private Map<String, String> templateParams;
    private String title;
    private String titleId;
    private String url;
    private String userId;

    /**
     * Default Constructor
     */
    public ActivityImpl() {
    }

    /**
     * Overriden Constructor
     */
    public ActivityImpl(String id, String userId) {
        this.id = id;
        this.userId = userId;
    }

    /**
     * Get a string specifying the application that this activity is associated with. Container
     * support for this field is REQUIRED.
     *
     * @return A string specifying the application that this activity is associated with
     */
    public String getAppId() {
        return appId;
    }

    /**
     * Set a string specifying the application that this activity is associated with. Container
     * support for this field is REQUIRED.
     *
     * @param appId A string specifying the application that this activity is associated with
     */
    public void setAppId(String appId) {
        this.appId = appId;
    }

    /**
     * Get a string specifying an optional expanded version of an activity. Container support for this
     * field is OPTIONAL.
     *
     * @return a string specifying an optional expanded version of an activity.
     */
    public String getBody() {
        return body;
    }

    /**
     * Set a string specifying an optional expanded version of an activity. Container support for this
     * field is OPTIONAL.
     * <p/>
     * Bodies may only have the following HTML tags:&lt;b&gt; &lt;i&gt;, &lt;a&gt;, &lt;span&gt;. The
     * container may ignore this formatting when rendering the activity.
     *
     * @param body a string specifying an optional expanded version of an activity.
     */
    public void setBody(String body) {
        this.body = body;
    }

    /**
     * Get a string specifying the body template message ID in the gadget spec. Container support for
     * this field is OPTIONAL.
     * <p/>
     * Bodies may only have the following HTML tags: &lt;b&gt; &lt;i&gt;, &lt;a&gt;, &lt;span&gt;. The
     * container may ignore this formatting when rendering the activity.
     *
     * @return a string specifying the body template message ID in the gadget spec.
     */
    public String getBodyId() {
        return bodyId;
    }

    /**
     * Set a string specifying the body template message ID in the gadget spec. Container support for
     * this field is OPTIONAL.
     *
     * @param bodyId a string specifying the body template message ID in the gadget spec.
     */
    public void setBodyId(String bodyId) {
        this.bodyId = bodyId;
    }

    /**
     * Get an optional string ID generated by the posting application. Container support for this
     * field is OPTIONAL.
     *
     * @return An optional string ID generated by the posting application.
     */
    public String getExternalId() {
        return externalId;
    }

    /**
     * Set an optional string ID generated by the posting application. Container support for this
     * field is OPTIONAL.
     *
     * @param externalId An optional string ID generated by the posting application.
     */
    public void setExternalId(String externalId) {
        this.externalId = externalId;
    }

    /**
     * Get a string ID that is permanently associated with this activity. Container support for this
     * field is OPTIONAL.
     *
     * @return a string ID that is permanently associated with this activity.
     */
    public String getId() {
        return id;
    }

    /**
     * Set a string ID that is permanently associated with this activity. Container support for this
     * field is OPTIONAL.
     *
     * @param id a string ID that is permanently associated with this activity.
     */
    public void setId(String id) {
        this.id = id;
    }

    /**
     * Get the last updated date of the Activity, additional to the Opensocial specification for the
     * REST-API. Container support for this field is OPTIONAL.
     *
     * @return the last updated date
     */
    public Date getUpdated() {
        if (updated == null) {
            return null;
        }
        return new Date(updated.getTime());
    }

    /**
     * . Set the last updated date of the Activity, additional to the Opensocial specification for the
     * REST-API. Container support for this field is OPTIONAL.
     *
     * @param updated the last updated date
     */
    public void setUpdated(Date updated) {
        if (updated == null) {
            this.updated = null;
        } else {
            this.updated = new Date(updated.getTime());
        }
    }

    /**
     * Get any photos, videos, or images that should be associated with the activity.
     * <p/>
     * Container support for this field is OPTIONAL.
     *
     * @return A List of {@link MediaItem} containing any photos, videos, or images that should be
     *         associated with the activity.
     */
    public List<MediaItem> getMediaItems() {
        return mediaItems;
    }

    /**
     * Set any photos, videos, or images that should be associated with the activity. Container
     * support for this field is OPTIONAL.
     * <p/>
     * Higher priority ones are higher in the list.
     *
     * @param mediaItems a list of {@link MediaItem} to be associated with the activity
     */
    public void setMediaItems(List<MediaItem> mediaItems) {
        this.mediaItems = mediaItems;
    }

    /**
     * Get the time at which this activity took place in milliseconds since the epoch. Container
     * support for this field is OPTIONAL.
     * <p/>
     * Higher priority ones are higher in the list.
     *
     * @return The time at which this activity took place in milliseconds since the epoch
     */
    public Long getPostedTime() {
        return postedTime;
    }

    /**
     * Set the time at which this activity took place in milliseconds since the epoch Container
     * support for this field is OPTIONAL.
     * <p/>
     * This value can not be set by the end user.
     *
     * @param postedTime the time at which this activity took place in milliseconds since the epoch
     */
    public void setPostedTime(Long postedTime) {
        this.postedTime = postedTime;
    }

    /**
     * Get the priority, a number between 0 and 1 representing the relative priority of this activity
     * in relation to other activities from the same source. Container support for this field is
     * OPTIONAL.
     *
     * @return a number between 0 and 1 representing the relative priority of this activity in
     *         relation to other activities from the same source
     */
    public Float getPriority() {
        return priority;
    }

    /**
     * Set the priority, a number between 0 and 1 representing the relative priority of this activity
     * in relation to other activities from the same source. Container support for this field is
     * OPTIONAL.
     *
     * @param priority a number between 0 and 1 representing the relative priority of this activity in
     *                 relation to other activities from the same source.
     */
    public void setPriority(Float priority) {
        this.priority = priority;
    }

    /**
     * Get a string specifying the URL for the stream's favicon. Container support for this field is
     * OPTIONAL.
     *
     * @return a string specifying the URL for the stream's favicon.
     */
    public String getStreamFaviconUrl() {
        return streamFaviconUrl;
    }

    /**
     * Set a string specifying the URL for the stream's favicon. Container support for this field is
     * OPTIONAL.
     *
     * @param streamFaviconUrl a string specifying the URL for the stream's favicon.
     */
    public void setStreamFaviconUrl(String streamFaviconUrl) {
        this.streamFaviconUrl = streamFaviconUrl;
    }

    /**
     * Get a string specifying the stream's source URL. Container support for this field is OPTIONAL.
     *
     * @return a string specifying the stream's source URL.
     */
    public String getStreamSourceUrl() {
        return streamSourceUrl;
    }

    /**
     * Set a string specifying the stream's source URL. Container support for this field is OPTIONAL.
     *
     * @param streamSourceUrl a string specifying the stream's source URL.
     */
    public void setStreamSourceUrl(String streamSourceUrl) {
        this.streamSourceUrl = streamSourceUrl;
    }

    /**
     * Get a string specifing the title of the stream. Container support for this field is OPTIONAL.
     *
     * @return a string specifing the title of the stream.
     */
    public String getStreamTitle() {
        return streamTitle;
    }

    /**
     * Set a string specifing the title of the stream. Container support for this field is OPTIONAL.
     *
     * @param streamTitle a string specifing the title of the stream.
     */
    public void setStreamTitle(String streamTitle) {
        this.streamTitle = streamTitle;
    }

    /**
     * Get a string specifying the stream's URL. Container support for this field is OPTIONAL.
     *
     * @return a string specifying the stream's URL.
     */
    public String getStreamUrl() {
        return streamUrl;
    }

    /**
     * Set a string specifying the stream's URL. Container support for this field is OPTIONAL.
     *
     * @param streamUrl a string specifying the stream's URL.
     */
    public void setStreamUrl(String streamUrl) {
        this.streamUrl = streamUrl;
    }

    /**
     * Get a map of custom key/value pairs associated with this activity. Container support for this
     * field is OPTIONAL.
     *
     * @return a map of custom key/value pairs associated with this activity.
     */
    public Map<String, String> getTemplateParams() {
        return templateParams;
    }

    /**
     * Set a map of custom key/value pairs associated with this activity. The data has type
     * {@link Map<String, Object>}. The object may be either a String or an {@link org.wso2.carbon.registry.social.api.people.userprofile.Person}. When
     * passing in a person with key PersonKey, can use the following replacement variables in the
     * template:
     * <ul>
     * <li>PersonKey.DisplayName - Display name for the person</li>
     * <li>PersonKey.ProfileUrl. URL of the person's profile</li>
     * <li>PersonKey.Id - The ID of the person</li>
     * <li>PersonKey - Container may replace with DisplayName, but may also optionally link to the
     * user.</li>
     * </ul>
     * Container support for this field is OPTIONAL.
     *
     * @param templateParams a map of custom key/value pairs associated with this activity.
     */
    public void setTemplateParams(Map<String, String> templateParams) {
        this.templateParams = templateParams;
    }

    /**
     * Get a string specifying the primary text of an activity. Container support for this field is
     * REQUIRED.
     * <p/>
     * Titles may only have the following HTML tags: &lt;b&gt; &lt;i&gt;, &lt;a&gt;, &lt;span&gt;. The
     * container may ignore this formatting when rendering the activity.
     *
     * @return a string specifying the primary text of an activity.
     */
    public String getTitle() {
        return title;
    }

    /**
     * Set a string specifying the primary text of an activity. Container support for this field is
     * REQUIRED.
     * <p/>
     * Titles may only have the following HTML tags: &lt;b&gt; &lt;i&gt;, &lt;a&gt;, &lt;span&gt;. The
     * container may ignore this formatting when rendering the activity.
     *
     * @param title a string specifying the primary text of an activity.
     */
    public void setTitle(String title) {
        this.title = title;
    }

    /**
     * Get a string specifying the title template message ID in the gadget spec. Container support for
     * this field is REQUIRED.
     * <p/>
     * The title is the primary text of an activity. Titles may only have the following HTML tags:
     * <&lt;b&gt; &lt;i&gt;, &lt;a&gt;, &lt;span&gt;. The container may ignore this formatting when
     * rendering the activity.
     *
     * @return a string specifying the title template message ID in the gadget spec.
     */
    public String getTitleId() {
        return titleId;
    }

    /**
     * Set a string specifying the title template message ID in the gadget spec. Container support for
     * this field is REQUIRED.
     * <p/>
     * The title is the primary text of an activity. Titles may only have the following HTML tags:
     * <&lt;b&gt; &lt;i&gt;, &lt;a&gt;, &lt;span&gt;. The container may ignore this formatting when
     * rendering the activity.
     *
     * @param titleId a string specifying the title template message ID in the gadget spec.
     */
    public void setTitleId(String titleId) {
        this.titleId = titleId;
    }

    /**
     * Get a string specifying the URL that represents this activity. Container support for this field
     * is OPTIONAL.
     *
     * @return a string specifying the URL that represents this activity.
     */
    public String getUrl() {
        return url;
    }

    /**
     * Set a string specifying the URL that represents this activity. Container support for this field
     * is OPTIONAL.
     *
     * @param url a string specifying the URL that represents this activity.
     */
    public void setUrl(String url) {
        this.url = url;
    }

    /**
     * Get a string ID of the user who this activity is for. Container support for this field is
     * OPTIONAL.
     *
     * @return a string ID of the user who this activity is for.
     */
    public String getUserId() {
        return userId;
    }

    /**
     * Get a string ID of the user who this activity is for. Container support for this field is
     * OPTIONAL.
     *
     * @param userId a string ID of the user who this activity is for.
     */
    public void setUserId(String userId) {
        this.userId = userId;
    }
}
